o1. First, you create an event object: 


   m_sockevent = WSACreateEvent(); 
   if (m_sockevent != WSA_INVALID_EVENT) { handle error.... } 


2. Tell Winsock which events you want to receive with your event object 
   by calling WSAEventSelect(): 


   int retval = WSAEventSelect(mySock, m_sockevent, FD_READ | FD_CLOSE); 
   if (retval == SOCKET_ERROR) { handle error.... } 


3. Get in a loop and wait for the events. This is preferably done within 
   a separate thread. Or just poll and replace WSA_INFINITE with 0 or a 
   desired timeout. Note that you also should check the error fields 
   returned by WSAEnumNetworkEvents() in the WSANETWORKEVENTS struct 
   (that's not done in my example): 


   DWORD            retval; 
   WSANETWORKEVENTS networkevents; 


   while(TRUE) { 
     retval = WSAWaitForMultipleEvents(1, &m_sockevent, TRUE, 
              WSA_INFINITE, FALSE); 
     if (retval == WSA_WAIT_EVENT_0) { 
       retval = WSAEnumNetworkEvents (mySock, m_sockevent, 
                &networkevents); 
       if (retval != SOCKET_ERROR){ 
         long events = networkevents.lNetworkEvents; 
         if ((events & FD_READ) != 0) { 
            Read from the socket for example... 
         }   
         if ((events & FD_CLOSE) != 0) { 
            Whatever you want to do here... 
         }   
         . 
         . 


